package com.atguigu.pratice;

import java.util.Scanner;

public class ThePokerCompare {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        String[] strings = s.split("-");
        String left = strings[0];
        String right = strings[1];
        //此时左右手牌已就位，此时要判断两种牌的类型
        //判定1:两边都是炸弹，两半只有一个炸弹，两边没有炸弹
        //写一个判断是否是炸弹的函数
        if (isBomb(left) && isBomb(right)) {
            System.out.println(isBombLager(left, right));
            return;
        } else if (isBomb(left) && (!isBomb(right))) {
            System.out.println(left);
            return;
        } else if (isBomb(right) && (!isBomb(left))) {
            System.out.println(right);
            return;
        } else {
            //两边都不是炸弹的情况
            //先写出一个函数，判断出牌的类型，我们可以根据牌的张数来进行判断
            String type1 = JudgeType(left);
            String type2 = JudgeType(right);
            if (!type1.equals(type2)) {
                System.out.println("ERROR");
                return;
            } else {
                //牌的类型相同
                //写一个函数，根据不同的type来制定比较规则，其中顺子的较为复杂
                String[] map = new String[]{"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K",
                        "A", "2"};
                int n1 = 0;
                int n2 = 0;
                if(type1.equals("Single")){
                    map=new String[]{"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K",
                            "A", "2","joker","JOKER"};
                    for(int i=0;i<map.length;i++){
                        if(left.equals(map[i])&&!right.equals(map[i])){
                            n1=i;
                        }else if(!left.equals(map[i])&&right.equals(map[i])){
                            n2=i;
                        }
                    }
                    if (n1 > n2) {
                        System.out.println(left);
                        return;
                    } else {
                        System.out.println(right);
                        return;
                    }
                }
                char[] chars1 = new char[]{left.charAt(0)};
                char[] chars2 = new char[]{right.charAt(0)};
                String s1 = new String(chars1);
                String s2 = new String(chars2);
                for (int i = 0; i < map.length; i++) {
                    if (s1.equals(map[i]) && (!s2.equals(map[i]))) {
                        n1 = i;
                    } else if (s2.equals(map[i]) && (!s1.equals(map[i]))) {
                        n2 = i;
                    }
                }
                if (n1 > n2) {
                    System.out.println(left);
                    return;
                } else {
                    System.out.println(right);
                }
            }
        }
    }

    //判断牌的类型
    private static String JudgeType(String str) {
        int realLength = 0;
        for (int i = 0; i < str.length(); i++) {
            if (str.charAt(i) != ' ') {
                realLength++;
            }
        }
        if(str.equals("10")){
            return "Single";
        }
        if(str.equals("joker")){
        return "Single";
    }
        if(str.equals("JOKER")){
        return "Single";
    }
        //得到长度
        //类型仅有单个，对子，三个，顺子(5个)
        if (realLength == 1) {
            return "Single";
        } else if (realLength == 2) {
            return "Pair";
        } else if (realLength == 3) {
            return "Three";
        } else
            return "Five";
    }

    //判断炸弹的函数
    public static boolean isBomb(String str){
        if(str.equals("joker JOKER")||str.equals("3 3 3 3")||str.equals("4 4 4 4")||
        str.equals("5 5 5 5")||str.equals("6 6 6 6")||str.equals("7 7 7 7")||
        str.equals("8 8 8 8")||str.equals("9 9 9 9")||str.equals("10 10 10 10")||
        str.equals("J J J J")||str.equals("Q Q Q Q")||str.equals("K K K K")||
        str.equals("A A A A")||str.equals("2 2 2 2")){
            return true;
        }else{
            return false;
        }
    }
    //比较炸弹大小的函数
    public static String isBombLager(String str1,String str2){
        String[] strings=new String[]{"3","4","5","6","7","8","9","10","J","Q","K",
        "A","2"};
        if(str1.equals("joker JOKER")&&(!str2.equals("joker JOKER"))){
            return str1;
        }else if(str2.equals("joker JOKER")&&(!str1.equals("joker JOKER"))){
            return str2;
        }else{
            //定位一下两个字符串各是什么炸
            char[] chars1=new char[]{str1.charAt(0)};
            char[] chars2=new char[]{str2.charAt(0)};
            String s1=new String(chars1);
            String s2=new String(chars2);
            int n1=0;
            int n2=0;
            for(int i=0;i< strings.length;i++){
                if(s1.equals(strings[i])&&(!s2.equals(strings[i]))){
                    n1=i;
                }else if(s2.equals(strings[i])&&(!s1.equals(strings[i]))){
                    n2=i;
                }
            }
            if(n1>n2){
                return str1;
            }else{
                return str2;
            }
        }
    }
}
